package com.xuelang.pipeline.artifact.app.harborv2;

import com.xuelang.pipeline.artifact.app.harborv2.config.HarborV2FeignConfig;
import com.xuelang.pipeline.artifact.app.harborv2.fallback.WebhookServiceFallbackFactory;
import com.xuelang.pipeline.artifact.app.harborv2.request.CreateWebhookPolicyRequest;
import com.xuelang.pipeline.artifact.app.harborv2.request.ListWebhookPolicyQuery;
import com.xuelang.pipeline.artifact.app.harborv2.response.ListWebhookPolicyResponse;
import com.xuelang.pipeline.artifact.app.nexus3v1.xo.ApiResponseXO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import jakarta.validation.Valid;
import java.util.List;

/**
 * 封装Docker v2.11.0-70255684以上项目相关接口-对应webhook
 *
 * @author xiwen.zxg
 * @since 2024/7/9
 */
@FeignClient(
        name = "webhook-service",
        url = "${feign.rpc.harborV2Service}",
        configuration = HarborV2FeignConfig.class,
        fallbackFactory = WebhookServiceFallbackFactory.class)
public interface WebhookService {
    /**
     * 查询项目webhook列表
     *
     * @param projectNameOrId
     * @param query
     *
     * @return
     */
    @GetMapping(value = "/projects/{project_name_or_id}/webhook/policies", produces = "application/json;charset=utf-8")
    ApiResponseXO<List<ListWebhookPolicyResponse>> listProjectWebhook(@PathVariable("project_name_or_id") String projectNameOrId, @SpringQueryMap ListWebhookPolicyQuery query);


    /**
     * 创建项目webhook
     *
     * @param projectNameOrId
     * @param createWebhookPolicyRequest
     *
     * @return
     */
    @PostMapping(value = "/projects/{project_name_or_id}/webhook/policies", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createProjectWebhook(@PathVariable("project_name_or_id") String projectNameOrId, @RequestBody @Valid CreateWebhookPolicyRequest createWebhookPolicyRequest);


}
